package com.youyi.yyviewsdklibrary.Dialog.animator;

import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;

public class TranslateAlphaAnimator extends PopupAnimator {
    private float defTranslationX;
    private float defTranslationY;
    private float startTranslationX;
    private float startTranslationY;

    public TranslateAlphaAnimator(View view, int i, PopupAnimation popupAnimation) {
        super(view, i, popupAnimation);
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator
    public void initAnimator() {
        this.defTranslationX = this.targetView.getTranslationX();
        this.defTranslationY = this.targetView.getTranslationY();
        this.targetView.setAlpha(0.0f);
        applyTranslation();
        this.startTranslationX = this.targetView.getTranslationX();
        this.startTranslationY = this.targetView.getTranslationY();
    }


    private void applyTranslation() {
        int i = this.popupAnimation.ordinal();
        if (i == 1) {
            this.targetView.setTranslationX((float) (-this.targetView.getMeasuredWidth()));
        } else if (i == 2) {
            this.targetView.setTranslationY((float) (-this.targetView.getMeasuredHeight()));
        } else if (i == 3) {
            this.targetView.setTranslationX((float) this.targetView.getMeasuredWidth());
        } else if (i == 4) {
            this.targetView.setTranslationY((float) this.targetView.getMeasuredHeight());
        }
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator
    public void animateShow() {
        this.targetView.animate().translationX(this.defTranslationX).translationY(this.defTranslationY).alpha(1.0f).setInterpolator(new FastOutSlowInInterpolator()).setDuration((long) this.animationDuration).withLayer().start();
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator
    public void animateDismiss() {
        if (!this.animating) {
            observerAnimator(this.targetView.animate().translationX(this.startTranslationX).translationY(this.startTranslationY).alpha(0.0f).setInterpolator(new FastOutSlowInInterpolator()).setDuration((long) this.animationDuration).withLayer()).start();
        }
    }
}
